Developing with Local NuGet in Visual Studio in Offline Environments
TLDR
- When developing in an offline environment, avoid direct DLL references; use local NuGet package sources instead for better version management.
- You can add a local folder as a NuGet source via Visual Studio's "Package Sources" settings.
- Use the
nuget addcommand to publish custom.nupkgpackages to a designated local source folder. - If external NuGet packages are required, obtain them from a computer with internet access and place them into the local source folder in the offline environment.
- Never copy the contents of the
packagesfolder under apackages.configproject directory directly into a NuGet source, as it lacks the necessary NuGet metadata.
Why Configure a Local NuGet Source
In a closed development environment without internet access, manually downloading and referencing DLLs leads to version management difficulties and makes handling package dependencies challenging. If a project is managed via NuGet, package restoration will fail in an offline state. By configuring a local NuGet source, you can ensure the development environment has a stable package repository and resolve issues with inconsistent DLL versions.
Configuring a Local NuGet Package Source
When does this issue occur: When the development environment cannot access the internet and you need to install or restore NuGet packages.
In Visual Studio, you can configure a local source by following these steps:
- Open the NuGet Package Manager settings in Visual Studio.
- In the "Package Sources" option, you can see the default offline sources.
- Click the "+" button in the top right corner to add the specified local folder path to the source list.


Once configured, you can switch to this local path in the source menu at the top right when installing packages.

Extending Local Packages
When does this issue occur: When you need to provide a self-developed Class Library as a NuGet package for use in an offline environment.
To publish a package to a local folder, use nuget.exe to execute the following command:
nuget add {packagePath} -Source {sourcePath}{packagePath}: The path to your.nupkgfile.{sourcePath}: The path to the local NuGet source folder you configured.
Extending Packages from NuGet
When does this issue occur: When a project needs to use publicly available NuGet packages from the internet, but the development environment cannot connect to download them.
This method requires a computer with internet access to act as an intermediary:
- Install the required packages on a computer with internet access.
- Locate the package cache path in Windows (usually located at
%userprofile%\.nuget\packages). - Copy the package files and place them into the local source folder configured in the offline development environment.
WARNING
When installing NuGet packages in .NET Framework, the default is to use "packages.config". In this case, there will be a "packages" folder in the project root containing the installed packages. However, these packages do not contain complete NuGet metadata, so do not copy them from here into your configured local package source.
Change Log
- 2023-12-05 Initial document creation.
